﻿using UnityEngine;
using System.Collections;

public class nukePowerUp : powerUpBase
{
		private GameObject enemyShips;
		public GameObject[] hodorShips;
		// Use this for initialization
		protected override void Start ()
		{
				FullHeal ();
				base.Start();
		}
		protected override void Update ()
		{
			enemyShips = GameObject.FindGameObjectWithTag ("Spawned");
			hodorShips =  GameObject.FindGameObjectsWithTag("HodorSpawn");
			base.Update ();
		}
		protected override void activatePowerUp ()
		{
				if (GameObject.FindGameObjectsWithTag ("orbit") != null) {
						GameObject[] orbits = GameObject.FindGameObjectsWithTag ("orbit");
						foreach (GameObject myOrbit in orbits) {
								myOrbit.gameObject.GetComponent<orbit> ().Die ();
						}
				}
				if(enemyShips!= null)
				{
					foreach (Transform enemyShipRef in enemyShips.transform) {
							if (enemyShipRef.gameObject != null) 
							{
								if(enemyShipRef.gameObject.GetComponent<AIBase> () != null)
								{
									enemyShipRef.gameObject.GetComponent<AIBase> ().Die ();
								}
							}

							if (enemyShipRef.childCount > 1) {
									enemyShipRef.GetChild (1).gameObject.GetComponent<AIBase> ().Die ();
							}
					}
				}
			if(hodorShips != null) 
			{
				foreach(GameObject child in hodorShips)
				{
					if (child.gameObject.GetComponent<CanTakeDamage>() != null)
					{
						child.gameObject.GetComponent<CanTakeDamage>().Die ();
					}
				}
			}
		}
}
